package com.itqf.service.impl;

import com.itqf.dao.UserDao;
import com.itqf.dao.impl.UserDaoImpl;
import com.itqf.entity.User;
import com.itqf.service.UserService;

import java.sql.SQLException;

public class UserServiceImpl implements UserService {
    @Override
    public boolean checkedUser(String username) throws SQLException {
        UserDao userDao = new UserDaoImpl();
        User user = userDao.selectUserByUsername(username);
        if(user!=null){
            return true;
        }

        return false;
    }

    @Override
    public int registerUser(User user) throws SQLException {
        UserDao userDao = new UserDaoImpl();
        int rows = userDao.insertUser(user);

        return rows;
    }

    @Override
    public User login(String username, String userpassword) throws SQLException {
        UserDao userDao = new UserDaoImpl();
        User user = userDao.selectUserByUsername(username);
        if(user!=null&&user.getUserpassword().equals(userpassword)){
            return user;
        }

        return null;
    }
}
